package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.LogLoginDto;
import com.huilian.iotbox.data.po.LogManipulate;
import com.huilian.iotbox.data.service.LogManipulateService;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/5/17 17:25
 */
@RestController
@RequestMapping("/api/logManipulate")
public class LogManipulateController extends BaseController {
    @Resource
    private LogManipulateService logManipulateService;
    @Resource
    private UserService userService;
    @GetMapping("/list")
    public ServerResponse list(HttpServletRequest request, LogManipulate logManipulate) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        logManipulate.setUserInfo(userInfo);
        return logManipulateService.findListByKeyword(logManipulate);
    }
    /**
     * 删除操作日志
     *
     * @return
     */
    @DeleteMapping("/{id}")
    public ServerResponse delete(HttpServletRequest request, @PathVariable Integer id) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logManipulateService.delete(id);
    }

    /**
     * 删除操作日志
     *
     * @return
     */
    @PostMapping("/batchDeleteInIds")
    public ServerResponse deleteInIds(HttpServletRequest request, @RequestBody LogLoginDto logLoginDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logManipulateService.batchDelete(logLoginDto);
    }


    /**
     * 删除操作日志
     *
     * @return
     */
    @PostMapping("/deleteInStartAndEndDateTime")
    public ServerResponse deleteInStartAndEndDateTime(HttpServletRequest request, @RequestBody LogLoginDto logLoginDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logManipulateService.deleteInStartAndEndDateTime(logLoginDto);
    }
}
